<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-item label="医生" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['name']" disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24" >
            <a-form-item label="认证状态" :labelCol="labelCol" :wrapperCol="wrapperCol" hasFeedback>
              <a-input
                v-decorator="[ 'faceStatus', validatorRules.faceStatus]">
              </a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['createTime']" disabled="disabled"></a-input>
            </a-form-item>
          </a-col>
<!--   认证信息  -->
          <a-row>
            <a-col :span="24" >
              <a-form-item label="认证信息：" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-row>
                  <a-col :span="8"> &nbsp;   &nbsp;执照正面
                   <j-image-upload  v-decorator="['license1']" disabled="disabled"></j-image-upload>
                  </a-col>
                  <a-col :span="8">&nbsp;&nbsp;
                    执照反面<j-image-upload v-decorator="['license2']" disabled="disabled"></j-image-upload>
                  </a-col>
                  <a-col :span="8">&nbsp;&nbsp;
                    资格证正面<j-image-upload  v-decorator="['qualification1']" disabled="disabled"></j-image-upload>
                  </a-col>
                  <a-col :span="8">&nbsp;&nbsp;
                    资格证反面<j-image-upload  v-decorator="['qualification2']" disabled="disabled"></j-image-upload>
                  </a-col>
                  <a-col :span="8">&nbsp;&nbsp;
                    专业技术资格证正面<j-image-upload  v-decorator="['technology1']" disabled="disabled"></j-image-upload>
                  </a-col>
                  <a-col :span="8">&nbsp;&nbsp;
                    专业技术资格证反面
                    <j-image-upload  v-decorator="['technology2']" disabled="disabled"></j-image-upload>
                  </a-col>
                </a-row>
              </a-form-item>
            </a-col>
          </a-row>


          <!--   认证按钮 -->
          <a-col :span="24">
            <template>
              <div style="padding-left: 150px;">
                <a-form-item>
                  <a-radio-group v-model="value" v-decorator="['certificationStatus']" @change="changeMe">
                    <a-radio :value="2">
                      审核通过
                    </a-radio>
                    <a-radio :value="3">
                      审核失败
                    </a-radio>
                  </a-radio-group>
                </a-form-item>
              </div>
            </template>
          </a-col>
          <!--   认证按钮end -->
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@comp/jeecg/JFormContainer'
  import JDate from '@comp/jeecg/JDate'
  import JImageUpload from '@comp/jeecg/JImageUpload'
  import ImgDragSort from '@views/jeecg/ImgDragSort'

  export default {
    name: 'DoctorCertificationForm',
    components: {
      ImgDragSort,
      JFormContainer,
      JDate,
      JImageUpload,
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,

        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},

        value:2,
        radioStyle: {
          display: 'block',
          height: '30px',
          lineHeight: '30px',
        },

        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {},
        url: {
          add: "/doctor/doctorCertification/add",
          edit: "/doctor/doctor/edit",
          queryById: "/doctor/doctorCertification/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      changeMe(){
       let ar = '';

        if(this.value == 2){
          ar = '已认证'
        }else if(this.value ==3){
          ar = '认证失败'
        }
        this.form.setFieldsValue({
          faceStatus: ar
        })
      },

      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          var vobj  = pick(this.model,'name','license1','license2','qualification1','qualification2','technology1','technology2','createBy','createTime','updateBy','updateTime','checkUser','checkTime','certificationStatus')
          vobj.certificationStatus = vobj.certificationStatus.toString();
          this.form.setFieldsValue(vobj)


        })
      },



      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)

            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })

          }
        })
      },
      popupCallback(row){
        var vobj =  pick(row,'name','license1','license2','qualification1','qualification2','technology1','technology2','createBy','createTime','updateBy','updateTime','checkUser','checkTime','certificationStatus')
        vobj.certificationStatus = vobj.certificationStatus.toString();
        this.form.setFieldsValue(vobj)
      },
    }
  }
</script>
